//
// Created by madison on 2022/6/18.
//
#include <iostream>
#include <vector>

using namespace std;

class Solution {
public:
    static int removeDuplicates(vector<int> &nums) {
        int n = nums.size();
        if (n == 0) {
            return 0;
        }
        int fast = 1, slow = 1;
        while (fast < n) {
            if (nums[fast] != nums[fast - 1]) {
                nums[slow] = nums[fast];
                ++slow;
            }
            ++fast;
        }
        return slow;
    }

    static int removeDuplicates1(vector<int> &nums) {
        int n = nums.size();
        if (n == 0) {
            return 0;
        }
        int left = 0, right = 1;
        while (right < n) {
            if (nums[left] != nums[right]) {
                left++;
                nums[left] = nums[right];
            }
            right++;
        }
        return ++left;
    }
};

int main() {
    vector<int> nums = {0, 0, 1, 1, 1, 2, 2, 3, 3, 4};
    int n = Solution::removeDuplicates1(nums);
    cout << n << endl;
    return 0;
}